﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CBE.Services;
using CBE.Model;
using Common.UI.EM;
using CBE.UI.Control.Views;
using System.Windows.Threading;
using System.Threading;

namespace CBE.UI.Control
{
    public class AdministrarVentasController : GenericEntityController<AdministrarVentasServiceLogic, Ventas, AdministrarVentasCriteria, AdministrarVentasView>
    {
        public override string Title
        {
            get
            {
                return "Administrar ventas";
            }
        }

        protected override void CreateEntityPresentationModel()
        {
            this.EntityPresentationModel = new AdministrarVentasEntityPresentationModel(base.CreateFilterView(), base.CreateListView(), base.CreateDetailView());
        }

        protected override Common.UI.EM.Views.DetailDataView CreateDetailDataView()
        {
            return new AdministrarVentasDetailDataView();
        }

        protected override Common.UI.EM.Views.FilterDataView CreateFilterDataView()
        {
            return new AdministrarVentasFilterDataView();
        }

        protected override void AddColumnDefinitions()
        {
            this.EntityPresentationModel.AddColumnDefinition(AdministrarVentasView.NroDocumentoClientePropertyName, "Nro. documento");
            this.EntityPresentationModel.AddColumnDefinition(AdministrarVentasView.NombreApellidoPropertyName, "Nombre y Apellido");
            this.EntityPresentationModel.AddColumnDefinition(AdministrarVentasView.FechaVentaStringPropertyName, "Fecha venta");
            this.EntityPresentationModel.AddColumnDefinition(AdministrarVentasView.ImporteServicioPropertyName, "Importe servicios");
            this.EntityPresentationModel.AddColumnDefinition(AdministrarVentasView.ImporteBonificadoPropertyName, "Bonificación");
            this.EntityPresentationModel.AddColumnDefinition(AdministrarVentasView.ImporteProductosPropertyName, "Importe productos");
            this.EntityPresentationModel.AddColumnDefinition(AdministrarVentasView.ImporteTotalPropertyName, "Importe total");
        }

        protected override void RegisterCustomEventHandlers()
        {
            ((AdministrarVentasEntityPresentationModel)this.EntityPresentationModel).ClienteNuevoCalled += new EventHandler(AdministrarVentasController_ClienteNuevoCalled);
        }

        void AdministrarVentasController_ClienteNuevoCalled(object sender, EventArgs e)
        {
            Thread controllerThread = new Thread(new ThreadStart(
                        delegate
                        {
                            ((System.Windows.UIElement)this.EntityManagerView).Dispatcher.Invoke(DispatcherPriority.Normal, new Action<object>(RunAdministrarClientesThreaded), null);
                        }
                    ));

            controllerThread.Start();
        }

        void RunAdministrarClientesThreaded(Object o)
        {
            AdministrarClientesController controller = new AdministrarClientesController();

            controller.RunInAdd();
        }

    }
}
